﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushJScript.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCore.css" />
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCoreEclipse.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>数据库的配置</h3>
    
    1.配置。在BaseController下重写GetDBConnection函数
    <pre class="brush:csharp;">
        //.net framewok下父类为OwinAction
        //.net core下父类为CoreAction
        using NFinal;
        namespace SimpleWebApp
        {
            public BaseController : OwinAction//或者CoreAction
            {
                public override IDbConnection GetDbConnection()
                {
                    System.Data.IDbConnection con=new System.Data.SqlClient.SqlConnection("此处填写连接字符串");
                    return con;
                }
            }
        }
    </pre>
    2.使用Dapper操作数据库。
    <pre class="brush:csharp;">
        using NFinal;
        using Dapper;
        namespace SimpleWebApp.Controllers
        {
            public void Index()
            {
                this.ViewBag.Title="首页";
                this.ViewBag.Message="HelloWorld!";
                //不需要手动打开与关闭数据库连接。直接使用即可
                var users = this.con.QueryAll("select * from users");
            }
        }
    </pre>
</body>
</html>